/
InstallBlocker.cs
62 lines (53 loc) · 1.88 KB
/
InstallBlocker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Services.Installer.Blocker
{
using System;
using System.IO;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities.Internal;
using DotNetNuke.Framework;
/// <summary>This class ...</summary>
public class InstallBlocker : ServiceLocator<IInstallBlocker, InstallBlocker>, IInstallBlocker
{
private const string InstallBlockerFile = "\\installBlocker.lock";
private bool fileCreated = false;
/// <inheritdoc/>
public void RegisterInstallBegining()
{
if (!this.fileCreated)
{
File.Create(Globals.ApplicationMapPath + InstallBlockerFile);
}
this.fileCreated = true;
}
/// <inheritdoc/>
public bool IsInstallInProgress()
{
return this.fileCreated || File.Exists(Globals.ApplicationMapPath + InstallBlockerFile);
}
/// <inheritdoc/>
public void RegisterInstallEnd()
{
var retryable = new RetryableAction(
() =>
{
if (this.IsInstallInProgress() && this.fileCreated)
{
File.Delete(Globals.ApplicationMapPath + InstallBlockerFile);
}
},
"Deleting lock file",
60,
TimeSpan.FromSeconds(1));
retryable.TryIt();
this.fileCreated = false;
}
/// <inheritdoc/>
protected override Func<IInstallBlocker> GetFactory()
{
return () => new InstallBlocker();
}
}
}